define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'admin/paymentActivityPrize/index?activity_id=' + window.activityId + '&user_id=' + window.userId,
        export_url: 'admin/paymentActivityPrize/export?activity_id=' + window.activityId + '&user_id=' + window.userId,
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'export'],
                cols: [[
                    {field: 'a.prize_sn', title: '中奖编号', hide: true},
                    {field: 'b.nickname', title: '昵称', hide: true},
                    {field: 'o.name', title: '姓名', hide: true},
                    {field: 'o.phone', title: '手机号', hide: true},

                    {field: 'prize_sn', title: '中奖编号', search: false},
                    {field: 'a', title: '会员信息', search: false, templet: function (d) {
                        var text  = "昵称：" + d.nickname + "<br />"
                            + "openid：" + d.openid + "<br />"
                        if (typeof d.order_info.name !== "undefined" && d.order_info.name !== null && d.order_info.name !== "") {
                            text = text + "姓名：" + d.order_info.name + "<br />";
                        }
                        if (typeof d.order_info.phone !== "undefined" && d.order_info.phone !== null && d.order_info.phone !== "") {
                            text = text + "手机号：" + d.order_info.phone + "<br />";
                        }
                        if (typeof d.order_info.customer_type !== "undefined" && d.order_info.customer_type !== null && d.order_info.customer_type !== "") {
                            text = text + "客户类型：" + d.order_info.customer_type;
                        }
                        return text;
                    }},
                    {field: 'b', title: '中奖信息', search: false, templet: function (d) {
                        return "中奖时间：" + d.create_time + "<br />"
                            + "中奖奖品：" + d.prize_name + "<br />"
                            + "领取状态：" + ((d.receive_status === 0) ? '未领取' : ((d.receive_status === 1) ? '已领取' : '')) + "<br />"
                            + "核销状态：" + ((d.status === 0) ? '未核销' : ((d.status === 1) ? '已作废' : ((d.status === 2) ? '已核销' : '')))
                    }},
                    {field: 'c', title: '所属活动', search: false, templet: function (d) {
                        return d.activity_title + "<br />"
                            + "所属商家：" + d.staff_nickname
                    }},
                    // {title: '中奖信息', search: false, templet: function (d) {
                    //     var text = "";
                    //     if (typeof d.order_info.name !== "undefined" && d.order_info.name !== null && d.order_info.name !== "") {
                    //         text = text + d.order_info.name + "<br />";
                    //     }
                    //     if (typeof d.order_info.phone !== "undefined" && d.order_info.phone !== null && d.order_info.phone !== "") {
                    //         text = text + d.order_info.phone + "<br />";
                    //     }
                    //     if (typeof d.order_info.address !== "undefined" && d.order_info.address !== null && d.order_info.address !== "") {
                    //         text = text + d.order_info.address;
                    //     }
                    //     return text;
                    // }},
                    // {field: 'prize_name', title: '中奖商品', search: false},
                    // {field: 'staff_nickname', title: '所属商家', search: false},
                    // {field: 'activity_title', title: '所属活动', search: false},
                    // {field: 'create_time', title: '中奖时间', search: false},
                    // {field: 'receive_status', title: '领取状态', search: false, templet: function (d) {
                    //     if (d.receive_status === 0) {
                    //         return '未领取';
                    //     } else if (d.receive_status === 1) {
                    //         return '已领取';
                    //     }
                    // }},
                    // {field: 'status', title: '核销状态', search: false, templet: function (d) {
                    //     if (d.status === 0) {
                    //         return '未核销';
                    //     } else if (d.status === 1) {
                    //         return '已作废';
                    //     } else if (d.status === 2) {
                    //         return '已核销';
                    //     }
                    // }},
                    {width: 250, title: '操作', templet: "#buttonTpl"},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };

    return Controller;
});